﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using HiShing.TongDanGuanJia.DeviceProperties.Dto;
using HiShing.TongDanGuanJia.Devices;
using HiShing.TongDanGuanJia.Devices.Dto;
using HiShing.TongDanGuanJia.OnNetaApis.Dto;
using Newtonsoft.Json;
using RestSharp;
using System.Linq;
using System.Security.Policy;
using System.Threading.Tasks;

namespace HiShing.TongDanGuanJia.DeviceProperties
{
    public class DevicePropertyAppService : AsyncCrudAppService<DeviceProperty, DevicePropertyDto, string, PagedDevicePropertyResultRequestDto>, IDevicePropertyAppService
    {
        public DevicePropertyAppService(IRepository<DeviceProperty, string> repository) : base(repository)
        {
        }

        //public override async Task<PagedResultDto<DevicePropertyDto>> GetAllAsync(PagedDevicePropertyResultRequestDto input)
        //{
        //    return await Task.Run(() =>
        //    {
        //        var query = Repository.GetAll().Where(p=>p.DeviceId == input.DeviceId);

              
        //        var totalCount = query.Count();

        //        if(totalCount == 0)
        //        {

        //        }

        //        var entities = query.OrderBy(d => d.Sort).Skip(input.SkipCount).Take(input.MaxResultCount).ToList();

        //        return new PagedResultDto<DevicePropertyDto>(
        //            totalCount,
        //            entities.Select(MapToEntityDto).ToList()
        //        );
        //    });
        //}


        //private async Task  getDevicePropertyFromOneNet(string deviceId)
        //{
        //    var url = ConfigHelper.GetAppSetting("App", "OneNetServiceUrl");
        //    var appkey = ConfigHelper.GetAppSetting("App", "OneNetAppKey");

        //    var options = new RestClientOptions(url)
        //    {
        //        MaxTimeout = -1,
        //    };
        //    var client = new RestClient(options);

        //    var requestUrl = $"{url}/devices/{deviceId}";

        //    var request = new RestRequest(requestUrl, Method.Get);
        //    request.AddHeader("api-key", appkey);
        //    RestResponse response = await client.ExecuteAsync(request);
        //    var content = JsonConvert.DeserializeObject<ResponseContent<DeviceInfo>>(response.Content);

        //    Configuration.AppConfigurations.Get("")
           
        //}
    }
}
